home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’91 / MS Works Merge Enhancer / BuildPathname.cp < prev    next >
Encoding:
Text File  |  1990-07-29  |  3.0 KB  |  97 lines  |  [TEXT/MPS ]

  1. #include    <types.h>
  2. #include    <Quickdraw.h>
  3. #include    <Memory.h>
  4. #include    <Files.h>
  5. #include    <Resources.h>
  6. #include    <Packages.h>
  7. #include     <String.h>
  8. #include     <Strings.h>
  9. #include    <ToolUtils.h>
  10. #include "THyperXCmd.h"
  11.  
  12. Handle BuildPathname (TXCMDBlock *myParamPtr, StringPtr fName, short vRefNum)
  13. {
  14.  
  15. /*
  16.   This function is adapted from the FileToField XCMD in the Dartmouth XCMDs.
  17.   Given the name of a file and vRefNum as provided by SFGetFile, returns a
  18.   StringHandle containing the full path to the file.
  19. */
  20.  
  21.     char            fullPathName[256], tempStr[256];
  22.     short            theErr;
  23.     register HParmBlkPtr    myParamBlock=nil;
  24.     register CInfoPBPtr        myCInfoPB=nil;
  25.     register WDPBPtr        myWDPB=nil;
  26.  
  27.     if (myParamBlock=(HParmBlkPtr)NewPtr(sizeof(HParamBlockRec)))
  28.     {
  29. /*
  30.   Get the name of the volume pointed to by the vRefNum
  31. */
  32.         myParamBlock->volumeParam.ioNamePtr = (StringPtr)&tempStr;
  33.         myParamBlock->volumeParam.ioCompletion = nil;
  34.         myParamBlock->volumeParam.ioVRefNum = vRefNum;
  35.         myParamBlock->volumeParam.ioVolIndex = 0;  
  36.  
  37.         if (theErr=PBHGetVInfo(myParamBlock, false))
  38.             myParamPtr->SignalFileErr(theErr);
  39.         else
  40.         {
  41. /*
  42.   Now we need the Working Directory (WD) information because we're
  43.   going to step backwards from the file through all of the folders until
  44.   we reach the root directory.
  45. */
  46.             myWDPB=(WDPBPtr)myParamBlock;
  47.             myWDPB->ioVRefNum = vRefNum;
  48.             myWDPB->ioWDProcID = 0;
  49.             myWDPB->ioWDIndex = 0;
  50.             if (theErr=PBGetWDInfo(myWDPB, false))
  51.                 myParamPtr->SignalFileErr(theErr);
  52.             else
  53.             {
  54.                 myCInfoPB=(CInfoPBPtr)myParamBlock;
  55.                 myCInfoPB->dirInfo.ioFDirIndex = -1;
  56.                 if (theErr=PBGetCatInfo(myCInfoPB, false))
  57.                     myParamPtr->SignalFileErr(theErr);
  58.                 else
  59.                 {
  60. /*
  61.   Here starts the real work -- start to climb the tree by continually
  62.   looking in the ioDrParID field for the next directory above until we fail...
  63. */
  64.                     myCInfoPB->dirInfo.ioDrDirID=myCInfoPB->dirInfo.ioDrParID;
  65.                     p2cstr(myCInfoPB->dirInfo.ioNamePtr);
  66.                     strcpy(fullPathName, (char *)myCInfoPB->dirInfo.ioNamePtr);
  67.                     strcat(fullPathName, ":");
  68.                     p2cstr(fName);
  69.                     strcat(fullPathName, (char *)fName);
  70.                     while (myCInfoPB->dirInfo.ioDrParID)
  71.                     {
  72.                         myCInfoPB->dirInfo.ioDrDirID=myCInfoPB->dirInfo.ioDrParID;
  73. /*
  74.   Be careful of an error returned here -- it means the user chose a file on the
  75.   desktop level of this volume.  If this is the case, just stop here and return
  76.   "VolumeName:FileName"; otherwise loop until failure.
  77. */
  78.                         if(theErr=PBGetCatInfo(myCInfoPB, false)==noErr)
  79.                         {
  80.                             p2cstr(myCInfoPB->dirInfo.ioNamePtr);
  81.                             strcpy(tempStr, (char *)myCInfoPB->dirInfo.ioNamePtr);
  82.                             strcat(tempStr, ":");
  83.                             strcat(tempStr, fullPathName);
  84.                             strcpy(fullPathName, tempStr);
  85.                         }
  86.                         else
  87.                             break;
  88.                     }
  89.                     return (myParamPtr->PasToZero((StringPtr)c2pstr(fullPathName)));
  90.                 }                        /*if PBGetCatInfo worked OK*/
  91.             }                            /*if PBHGetVInfo worked OK*/
  92.         }                                /*if PBGetWDInfo worked OK*/
  93.         DisposPtr((Ptr)myParamBlock);
  94.     }                                    /*if we had enough room for a new pointer*/
  95.     return (nil);
  96. }
  97.